﻿
//function btn_addClick() {
//    $('Mymodal').show();
//}
var count = 0;
var count1 = 0;
var oBtn = document.getElementById('btn_submit');
oBtn.onclick = function(){
    //获取模态框数据
    var username = document.getElementById('username').value;
    var MainAddress = document.getElementById('addr-show').value;
    var detailsAddress = document.getElementById('detailsAddress').value;
    var Usertelephone = document.getElementById('Usertelephone').value;
    var table = document.getElementById('AddressTable');
    var deAddress = MainAddress + detailsAddress;
    var tr = document.createElement('tr'); 
    var td = document.createElement('td');
    var tableBody = document.getElementById('TableBody');
    td.setAttribute('width', '300px');
    tr.innerHTML = "<td>" + '<input  type="checkbox" class="CheckboxChoose" name="ChooseOne" />' + "</td>" + "<td>" + username + "</td>" + "<td>" + deAddress + "</td><td>" + Usertelephone + "</td>" + "<td>" + "<button onclick='modify(this)'>" + "修改" + "</button></td><td><button  >" + "删除" + "</button></td><td><button class='btn_choose'  id="+count+">选择</button></td>";
    tableBody.appendChild(tr);
    var ChooseOne = document.getElementsByClassName('CheckboxChoose');
    for (var i = 0; i < ChooseOne.length; i++)
    {
        ChooseOne[i].setAttribute("disabled", true);
    }
    var as = document.getElementsByClassName('btn_choose');
    for (var j = 0; j < as.length; j++) {
        as[j].onclick = function () {  //点击a 删除 当前a 所在的行（a链接的爸爸的爸爸）
            //    tableBody.removeChild(this.parentNode.parentNode);

            var tem = this.parentNode.parentNode.firstElementChild.firstElementChild;
            if (this.innerHTML == '选择') {
                tem.checked = true;
                this.innerHTML = '取消';
            }
            else {          
                tem.checked = false;
                this.innerHTML = '选择';
            }



            //var tem = $(this).parentNode.find("td").eq(1);
            //Response.wirte(tem);
            //tem.setAttribute("checked", true);
        }
    }


}

//count1 = count - 1;
//var as1 = document.getElementById(count1);
//as1.onclick = function () {
//    var as = document.getElementsByClassName('btn_choose');
//    for (var j = 0; j < as.length; j++) {
//        as[j].onclick = function () {  //点击a 删除 当前a 所在的行（a链接的爸爸的爸爸）
//            //    tableBody.removeChild(this.parentNode.parentNode);

//            var tem = this.parentNode.parentNode.firstElementChild.firstElementChild;
//            if (this.innerHTML == '选择') {
//                tem.setAttribute("checked", true);
//                this.innerHTML = '取消';
//            }
//            else {
//                tem.setAttribute('checked', false);
//                this.innerHTML = '选择';
//            }
//        }
//    }
//}





//$(function () {
//    $("input:checkbox").on("change", function () {
//        var objName = $(this).attr("name");   //获取name属性的值
//        var i = 0;
//        //依次遍历上下文所有的含有name='"+objName+"'的input
//        //each中index是当前元素的位置，element是值。
//        $("input[name='" + objName + "']").each(function (index, element) {
//            if ($(element).is(':checked')) {
//                i++;
//            }
//        });
//        if (i > 1) {
//            alert("地址只能选一个");
//            $(this).attr("checked", false)
//        }
//    });
//});

//function btn_select() {
//    var tem = $(this).parent().parent().find(".CheckboxChoose");
//    tem.attr("checked", true);
//}

//$('#AddressTable tr td CheckboxChoose').each(function () {
//    var tem = $(this).parent().parent().find(".CheckboxChoose");
//    tem.attr("checked", true);
//});

//$("table").on('click', '#btn_choose', function () {
//    var tem = $(this).parent("tr").find("#CheckboxChoose");
//    tem.setAttribute("checked", true);

//});



































